<template>
  <router-view/>
</template>

<script>
import { checkloginServer } from "./api/user";
import { mapMutations, mapActions } from "vuex";

export default {
  name: "app",

  methods: {
    ...mapMutations(["setUserState"]),
    ...mapActions(["setInterceptors"])
  },
  beforeMount() {
    this.setInterceptors();
    checkloginServer("post").then(
      suc => {
        const { code, data } = suc.data;
        if (code) {
          console.log(suc);
          this.$store.dispatch("setInterceptors");
          this.setUserState({
            isLogin: true,
            userData: {
              userId: data.userId,
              username: data.username,
              authority: data.authority
            }
          });
        } else {
          this.setUserState({ isLogin: false });
        }
      },
      err => {
        this.setUserState({ isLogin: false });
      }
    );
  }
};
</script>

<style lang="less">
@import "./assets/styles/index.less";
@--color-primary: teal;
</style>
